print "Generate positional sensitive IDF and IF info, focus on the whole evaluated collection."
import os
import itertools

print "generate all the variations of the query"

outputFileNameForTf_dict = "/data5/team/weijiang/the_new_trip_of_feature_generation/final-150Clueweb09Queries-variations.txt"
outputFileHandlerForTf_dict = open(outputFileNameForTf_dict,"w")


inputFileName = "/data5/team/weijiang/the_new_trip_of_feature_generation/final-150Clueweb09QueriesExceptThatOne.txt"
inputFileHandler = open(inputFileName,"r")
for line in inputFileHandler.readlines():
    elements = line.strip().split(":")
    queryID = elements[0]
    queryContent = elements[1]
    
    if len(queryContent.split(" ")) != 1:
        queryTermElements = queryContent.split(" ")
        queryLength = len(queryTermElements)
    else:
        queryTermElements = queryContent
        queryLength = 1
    
    # Let's do all the variations for this query
    # any possible subset larger than one of the query terms subset
    outputLineBase = queryID + "_" + "set" + " ";
    #counter = 0
    
    if queryLength != 1:
        for i in range(0+2,queryLength+1):
            for currentTuple in list(itertools.combinations(queryTermElements, i)):
                #counter += 1
                #outputLine = outputLineBase + "_"
                for currentSubsetElement in list(currentTuple)[:-1]:
                    outputLineBase += currentSubsetElement + "_"
                outputLineBase += list(currentTuple)[-1] + " "
    else:
        outputLineBase += queryContent + " ";
    
    outputFileHandlerForTf_dict.write(outputLineBase + "\n")
    print line.strip()
    print outputLineBase
    print 
    '''
    # Let's do all the variations for this query
    # any possible consecutive pair for this query
    outputLineBase = queryID + "_" + "pair";
    #counter = 0
    for index,queryTerm in enumerate(queryTermElements[:-1]):
        #counter += 1
        outputLine = outputLineBase + "_" + queryTermElements[index] + "_" + queryTermElements[index+1]
        outputFileHandlerForTf_dict.write(outputLine + "\n")
        print outputLine
    ''' 
        
        
inputFileHandler.close()
outputFileHandlerForTf_dict.close()
        

'''
basePath = "/data4/team/weijiang/human_judge_web_pages_plain_text_only_words/en0000"

inputFileName = ""

tempCounter = 0
for dirname, dirnames, filenames in os.walk(basePath):
    
    #for nameOfDir in dirnames:
    #    absoluteNameOfDir = os.path.join(dirname, nameOfDir)
    #    print "absoluteNameOfDir:",absoluteNameOfDir
        
    for index,filename in enumerate(filenames):
        absoluteFileName = os.path.join(dirname, filename)
        tempCounter += 1
        print absoluteFileName

print "tempCounter:",tempCounter            
print "Done"
'''

